<%@ page import="java.sql.ResultSet" %>
<%@ page import="java.sql.Statement" %>
<%@ page import="java.sql.DriverManager" %>
<%@ page import="java.sql.Connection" %>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <jsp:include page="head.jsp"/>
    <title>张渊新闻网</title>
    <style>
        . {
            background-image: url("images/bg.jpg");
        }

        .top-left {
            /*background-color: black;*/
            color: black;
            float: left;
            width: 30%;
            height: 500px;
            margin: 2% 2.3% 5px 2.4%;
        }

        .top-mid {
            /*background-color: black;*/
            color: black;
            float: left;
            width: 30%;
            height: 500px;
            /*margin: 2% 2.5% 5px 2.5%;*/
            margin-top: 2%;
            margin-bottom: 5px;
        }

        .top-right {
            /*background-color: black;*/
            color: black;
            width: 30%;
            height: 500px;
            float: right;
            margin: 2% 2.4% 5px 2.1%;
        }

        .top-right a, .top-mid a, .top-left a, .bottom-left a, .bottom-mid a, .bottom-right a {
            margin: 3% 0 1% 0;
            font-size: 22px;
            display: inline-block;
        }

        .top-left, .top-mid, .top-right, .bottom-left, .bottom-mid, .bottom-right {
            border: 2px black solid;
        }

        .container a:visited {
            color: black;
        }

        .container a:link{
            color: black;
        }
        .container  a:hover{
            color: red;
        }
        .bottom-left {
            /*background-color: black;*/
            color: black;
            float: left;
            width: 30%;
            height: 500px;
            margin: 2% 2.3% 5px 2.4%;
        }

        .bottom-mid {
            /*background-color: black;*/
            color: black;
            width: 30%;
            height: 500px;
            float: left;
            margin-top: 2%;
            margin-bottom: 5px;
        }

        .bottom-right {
            /*background-color: black;*/
            color: black;
            width: 30%;
            height: 500px;
            float: right;
            margin: 2% 2.4% 5px 2.1%;
        }
    </style>
</head>
<body>
<%
    try {
        Class.forName("com.mysql.jdbc.Driver");
        String url = "jdbc:mysql://localhost:3306/news?serverTimezone=UTC";
        String username1111 = "root";
        String password1111 = "root";
        Connection conn = DriverManager.getConnection(url, username1111, password1111);
%>

<div class="container">
    <div class="top-left">
        <h4 align="center">体育</h4>
        <%
            Statement stmt = null;
            ResultSet rs = null;
            String id, title, simply;
            String sql;
            if (conn != null) {
                sql = "SELECT id,title,simply FROM news where type='体育'  limit 4;";  //查询语句
                stmt = conn.createStatement();
                rs = stmt.executeQuery(sql);
                rs.next();
                id = rs.getString("id");
                title = rs.getString("title");
                simply = rs.getString("simply");
        %>
        <a href="news.jsp?id=<%=id%>"><%=title%>
        </a><br/>
        <%=simply%><br/><%
        rs.next();
        id = rs.getString("id");
        title = rs.getString("title");
        simply = rs.getString("simply");
    %>
        <a href="news.jsp?id=<%=id%>"><%=title%>
        </a><br/>
        <%=simply%><br/><%
        rs.next();
        id = rs.getString("id");
        title = rs.getString("title");
        simply = rs.getString("simply");
    %>
        <a href="news.jsp?id=<%=id%>"><%=title%>
        </a><br/>
        <%=simply%><br/><%
        rs.next();
        id = rs.getString("id");
        title = rs.getString("title");
        simply = rs.getString("simply");
    %>
        <a href="news.jsp?id=<%=id%>"><%=title%>
        </a><br/>
        <%=simply%><br/>

    </div>


    <div class="top-mid">
        <h4 align="center">娱乐</h4>
        <%
            }
            if (conn != null) {
                stmt = null;
                rs = null;
                sql = "SELECT id,title,simply FROM news where type='娱乐'  limit 4;";  //查询语句
                stmt = conn.createStatement();
                rs = stmt.executeQuery(sql);
                rs.next();
                id = rs.getString("id");
                title = rs.getString("title");
                simply = rs.getString("simply");
        %>
        <a href="news.jsp?id=<%=id%>"><%=title%>
        </a><br/>
        <%=simply%><br/><%
        rs.next();
        id = rs.getString("id");
        title = rs.getString("title");
        simply = rs.getString("simply");
    %>
        <a href="news.jsp?id=<%=id%>"><%=title%>
        </a><br/>
        <%=simply%><br/><%
        rs.next();
        id = rs.getString("id");
        title = rs.getString("title");
        simply = rs.getString("simply");
    %>
        <a href="news.jsp?id=<%=id%>"><%=title%>
        </a><br/>
        <%=simply%><br/><%
        rs.next();
        id = rs.getString("id");
        title = rs.getString("title");
        simply = rs.getString("simply");
    %>
        <a href="news.jsp?id=<%=id%>"><%=title%>
        </a><br/>
        <%=simply%><br/>
    </div>
    <div class="top-right">
        <h4 align="center">股票</h4>
        <% }
            if (conn != null) {
                stmt = null;
                rs = null;
                sql = "SELECT id,title,simply FROM news where type='股票'  limit 4;";  //查询语句
                stmt = conn.createStatement();
                rs = stmt.executeQuery(sql);
                rs.next();
                id = rs.getString("id");
                title = rs.getString("title");
                simply = rs.getString("simply");
        %>
        <a href="news.jsp?id=<%=id%>"><%=title%>
        </a><br/>
        <%=simply%><br/><%
        rs.next();
        id = rs.getString("id");
        title = rs.getString("title");
        simply = rs.getString("simply");
    %>
        <a href="news.jsp?id=<%=id%>"><%=title%>
        </a><br/>
        <%=simply%><br/><%
        rs.next();
        id = rs.getString("id");
        title = rs.getString("title");
        simply = rs.getString("simply");
    %>
        <a href="news.jsp?id=<%=id%>"><%=title%>
        </a><br/>
        <%=simply%><br/><%
        rs.next();
        id = rs.getString("id");
        title = rs.getString("title");
        simply = rs.getString("simply");
    %>
        <a href="news.jsp?id=<%=id%>"><%=title%>
        </a><br/>
        <%=simply%><br/>
    </div>
    <div class="bottom-left">
        <h4 align="center">财经</h4>
        <%
            }
            if (conn != null) {
                stmt = null;
                rs = null;
                sql = "SELECT id,title,simply FROM news where type='财经'  limit 4;";  //查询语句
                stmt = conn.createStatement();
                rs = stmt.executeQuery(sql);
                rs.next();
                id = rs.getString("id");
                title = rs.getString("title");
                simply = rs.getString("simply");
        %>
        <a href="news.jsp?id=<%=id%>"><%=title%>
        </a><br/>
        <%=simply%><br/><%
        rs.next();
        id = rs.getString("id");
        title = rs.getString("title");
        simply = rs.getString("simply");
    %>
        <a href="news.jsp?id=<%=id%>"><%=title%>
        </a><br/>
        <%=simply%><br/><%
        rs.next();
        id = rs.getString("id");
        title = rs.getString("title");
        simply = rs.getString("simply");
    %>
        <a href="news.jsp?id=<%=id%>"><%=title%>
        </a><br/>
        <%=simply%><br/><%
        rs.next();
        id = rs.getString("id");
        title = rs.getString("title");
        simply = rs.getString("simply");
    %>
        <a href="news.jsp?id=<%=id%>"><%=title%>
        </a><br/>
        <%=simply%><br/>
    </div>
    <div class="bottom-mid">
        <h4 align="center">汽车</h4>
        <%
            }
            if (conn != null) {
                stmt = null;
                rs = null;
                sql = "SELECT id,title,simply FROM news where type='汽车'  limit 4;";  //查询语句
                stmt = conn.createStatement();
                rs = stmt.executeQuery(sql);
                rs.next();
                id = rs.getString("id");
                title = rs.getString("title");
                simply = rs.getString("simply");
        %>
        <a href="news.jsp?id=<%=id%>"><%=title%>
        </a><br/>
        <%=simply%><br/><%
        rs.next();
        id = rs.getString("id");
        title = rs.getString("title");
        simply = rs.getString("simply");
    %>
        <a href="news.jsp?id=<%=id%>"><%=title%>
        </a><br/>
        <%=simply%><br/><%
        rs.next();
        id = rs.getString("id");
        title = rs.getString("title");
        simply = rs.getString("simply");
    %>
        <a href="news.jsp?id=<%=id%>"><%=title%>
        </a><br/>
        <%=simply%><br/><%
        rs.next();
        id = rs.getString("id");
        title = rs.getString("title");
        simply = rs.getString("simply");
    %>
        <a href="news.jsp?id=<%=id%>"><%=title%>
        </a><br/>
        <%=simply%><br/>
    </div>
    <div class="bottom-right">
        <h4 align="center">科技</h4>
        <%
            }
            if (conn != null) {
                stmt = null;
                rs = null;
                sql = "SELECT id,title,simply FROM news where type='科技'  limit 4;";  //查询语句
                stmt = conn.createStatement();
                rs = stmt.executeQuery(sql);
                rs.next();
                id = rs.getString("id");
                title = rs.getString("title");
                simply = rs.getString("simply");
        %>
        <a href="news.jsp?id=<%=id%>"><%=title%>
        </a><br/>
        <%=simply%><br/><%
        rs.next();
        id = rs.getString("id");
        title = rs.getString("title");
        simply = rs.getString("simply");
    %>
        <a href="news.jsp?id=<%=id%>"><%=title%>
        </a><br/>
        <%=simply%><br/><%
        rs.next();
        id = rs.getString("id");
        title = rs.getString("title");
        simply = rs.getString("simply");
    %>
        <a href="news.jsp?id=<%=id%>"><%=title%>
        </a><br/>
        <%=simply%><br/><%
        rs.next();
        id = rs.getString("id");
        title = rs.getString("title");
        simply = rs.getString("simply");
    %>
        <a href="news.jsp?id=<%=id%>"><%=title%>
        </a><br/>
        <%=simply%><br/>
    </div>
</div>
<%
        } else {
            out.print("连接数据库失败！");
        }
    } catch (Exception e) {
        out.print(e);
    }
%>
%>
</body>
</html>
